/*
 * Copyright (C) 2011 flashflexpro@gmail.com  All Rights Reserved.  No
 *   use, copying or distribution of this work may be made except in
 *   accordance with a valid license agreement from flashflexpro@gmail.com
 *   This notice must be included on all copies, modifications and
 *   derivatives of this work.
 *
 *   flashflexpro@gmail.com MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT
 *   THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
 *   INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 *   NON-INFRINGEMENT. flashflexpro@gmail.com SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED
 *   BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS
 *   SOFTWARE OR ITS DERIVATIVES.
 */

package {
import mx.collections.ArrayCollection;
import mx.collections.ListCollectionView;
import mx.collections.Sort;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;

public class TestsEntry {
    [Test]
    public function testListCollectionView():void {
        var aaa:ArrayCollection = new ArrayCollection([ 0, 1, 2, 3, 4, 5 ]);
        var bbb:ArrayCollection = new ArrayCollection([ new XML( "<5/>" ), new XML( "<4/>" ), new XML( "<3/>" ), new XML( "<2/>" ), new XML( "<1/>" ), new XML( "<0/>" )]);

        aaa.addEventListener(CollectionEvent.COLLECTION_CHANGE, onChange);
        bbb.addEventListener(CollectionEvent.COLLECTION_CHANGE, onChange);

        aaa.addItemAt("A", 3);

        var s:Sort = new Sort();
        s.compareFunction = function(aa:XML, bb:XML, fields:Array = null):int{
            var aaa:String = aa.toXMLString();
            var aaaa:String = aaa.substr( 1, 1 );
            var bbb:String = bb.toXMLString();
            var bbbb:String = bbb.substr( 1, 1 );
            var a:int = int(aaaa );
            var b:int = int(bbbb );
            if( a > b){
                return 1;
            }
            if( a < b ){
                return -1;
            }
            return 0;
        };
        
        bbb.sort = s;
        if( !bbb.refresh() ){
            throw new Error( "not finish!" );
        }
        trace( bbb );


        bbb.setItemAt( new XML( "<6/>" ), 0 );
        trace( "6:" + bbb );

        bbb.setItemAt( new XML( "<9/>" ), 0 );
        trace( "9:" + bbb );
        bbb.setItemAt( new XML( "<7/>" ), 0 );
        trace( "7:" + bbb );
        bbb.setItemAt( new XML( "<8/>" ), 0 );
        trace( "8:" + bbb );
        bbb.setItemAt( new XML( "<11/>" ), 0 );
        trace( "11:" + bbb );
        bbb.setItemAt( new XML( "<10/>" ), 0 );
        trace( "10:" + bbb );


    }

    private function onChange(event:CollectionEvent):void {
        trace(event.type + "]["+ event.kind + "][" + event.items + "]["+ event.location + "]["+ event.oldLocation + "][" + event.target );
        
        if (event.kind == CollectionEventKind.ADD) {
        }
        else if (event.kind == CollectionEventKind.MOVE) {

        }
        else if (event.kind == CollectionEventKind.REFRESH) {

        }
        else if (event.kind == CollectionEventKind.REMOVE) {

        }
        else if (event.kind == CollectionEventKind.REPLACE) {

        }
        else if (event.kind == CollectionEventKind.RESET) {

        }
        else if (event.kind == CollectionEventKind.UPDATE) {

        }
    }
}

}
